package com.resource;

import java.util.ResourceBundle;

public class ResourceBundleManager {
	private static final  String RESOURCE_FILE = "tool.config.resource";
	
	private static ResourceBundle bundle;
	
	protected static String getStringValue(String key, String defaultValue){
		try{
			if (bundle == null){
				bundle = ResourceBundle.getBundle(RESOURCE_FILE); 
			}
			return bundle.getString(key);
		}catch(java.util.MissingResourceException e){
			return defaultValue;
		}
	}
	
	protected static int getIntValue(String key, int defaultValue){
		try{
			String val = getStringValue(key, null);
			if(val != null){
				return Integer.parseInt(val);
			}else{
				return defaultValue;
			}
		}catch(NumberFormatException e){
			return defaultValue;
		}
	}
	
	protected static long getLongValue(String key, int defaultValue){
		try{
			String val = getStringValue(key, null);
			if(val != null){
				return Long.parseLong(val);
			}else{
				return defaultValue;
			}
		}catch(NumberFormatException e){
			return defaultValue;
		}
	}
}
